package geom;

import geom.Line;
import geom.Vector;

import java.util.ArrayList;
import java.util.Iterator;


import processing.core.PApplet;

public class VectorDraw extends PApplet{
	ArrayList<TangentLine> lines;
	TangentLine line;
	
	public void setup(){
		size(600, 600);
		frameRate(6);
		smooth();
		lines = new ArrayList<TangentLine>();
		line = null;
	}
	
	
	public void draw(){
		background(0);
		Iterator<TangentLine> i = lines.iterator();
		noFill();
		while(i.hasNext()){
			TangentLine next = i.next();
			stroke(90, 220, 100);
			next.draw(this);
			//stroke(30, 120, 200);
			//next.drawHeadings(this);
		}
		if(line != null){
			stroke(90, 150, 100);
			line.draw(this);
			//stroke(30, 160, 240);
			//line.drawHeadings(this);
		}
		if(field != null){
			stroke(255, 70);
			field.draw(this, 700, 700, 14);
		}
	}
	AngleField field = null; 
	
	public void mousePressed(){
		line = new TangentLine();
	}
	
	public void mouseReleased(){
		lines.add(line);
		field = new AngleField(getAll());
		line = null;
	}
	
	public ArrayList<Line> getAll(){
		ArrayList<Line> all = new ArrayList<Line>();
		Iterator<TangentLine> il = lines.iterator();
		while(il.hasNext()) all.addAll(il.next().getLines());
		return all;
	}
	
	public void mouseDragged(){
		line.add(new Vector(mouseX, mouseY));
	}
	

}
